import { Statement, STATEMENT_KIND, STATEMENT_TAG } from '../statement';
import { DropBehavior } from './types';

export class DropDatabase extends Statement {
  $kind: STATEMENT_KIND.DROP_DATABASE = STATEMENT_KIND.DROP_DATABASE;
  $name: string;
  $tag: STATEMENT_TAG.EXECUTABLE = STATEMENT_TAG.EXECUTABLE;
  $behavior: DropBehavior = 'DROP';

  static isDropDatabase(object: any): object is DropDatabase {
    return (
      Statement.isStatement(object) &&
      object.$kind === STATEMENT_KIND.DROP_DATABASE
    );
  }

  constructor(name: string) {
    super();
    this.$name = name;
  }
}

export function DropDatabaseBuilder(name: string): DropDatabase {
  return new DropDatabase(name);
}

DropDatabaseBuilder.ifExists = function (name: string): DropDatabase {
  const statement = DropDatabaseBuilder(name);
  statement.$behavior = 'DROP_IF_EXISTS';
  return statement;
};

export type DropDatabaseBuilder = typeof DropDatabaseBuilder;
